/**
 * module store 基类
 */
import Vue from 'vue'
export default {
  state: {},
  mutations: {
    // 设置状态数值，通过code指定数据路径，若无code，则视为重置整个state的值
    setState(state, {code, data}) {
      if (code !== undefined && code !== null) {
        let arr = code.split('.')
        let name = arr.pop()
        var node = state
        for (let i in arr) {
          if (node !== undefined) {
            node = node[arr[i]]
          } else {
            break
          }
        }
        if (node !== undefined) {
          Vue.set(node, name.data)
        }
      } else {
        state = data
      }
    }
  }
}
